import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.preprocessing import PolynomialFeatures
from sklearn.linear_model import LinearRegression
from sklearn.pipeline import make_pipeline
# 读取数据
df = pd.read_excel(r"water_tu/IS on CH4.xlsx", sheet_name="Daily")

# 提取叶绿素a和DOC对CH4的影响强度
chla_impact = df['IS_Chla'].values
doc_impact = df['IS_DOC'].values

# # 对叶绿素a影响强度进行傅里叶变换
# fft_chla = np.fft.fft(chla_impact)
# freqs_chla = np.fft.fftfreq(len(chla_impact), d=1)
#
# # 对DOC影响强度进行傅里叶变换
# fft_doc = np.fft.fft(doc_impact)
# freqs_doc = np.fft.fftfreq(len(doc_impact), d=1)
#
# # 绘制叶绿素a和DOC的频谱在同一张图中
# plt.figure(figsize=(10, 6))
#
# # 叶绿素a的频谱
# plt.plot(freqs_chla, np.abs(fft_chla), label='Chla Impact FFT', color='blue')
#
# # DOC的频谱
# plt.plot(freqs_doc, np.abs(fft_doc), label='DOC Impact FFT', color='orange')
#
# # 设置图表标题和标签
# plt.title('FFT of Chlorophyll-a and DOC Impacts on CH4')
# plt.xlabel('Frequency')
# plt.ylabel('Magnitude')
# plt.xlim(0, 0.05)  # 选择合适的频率范围
# plt.legend()
#
# # 显示图表
# plt.show()


diff_value = abs(chla_impact) - (doc_impact)
fft_diff = np.fft.fft(diff_value)
freqs_diff = np.fft.fftfreq(len(diff_value), d=1)

plt.figure(figsize=(10, 6))

# 叶绿素a的频谱
plt.plot(freqs_diff, np.abs(fft_diff), label='Diff Impact FFT', color='blue')

# 设置图表标题和标签
plt.title('FFT of Diff of Chlorophyll-a and DOC Impacts on CH4')
plt.xlabel('Frequency')
plt.ylabel('Magnitude')
plt.xlim(0, 0.025)  # 选择合适的频率范围
plt.legend()

# 显示图表
plt.show()

